<style type="text/css">
  .layui-body{overflow-y: scroll;}
  body{overflow-y: scroll;}
</style>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">投诉建议</a>
        <a>
          <cite>建议列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <xblock style="height: 40px;">
        <div style="float: left">
        <button class="layui-btn layui-btn-disabled suggest_store_list"  onclick="x_admin_show('门店管理','suggest_store_list',800,600)">门店管理</button>
        <button class="layui-btn layui-btn-danger layui-btn-disabled tech_work_list"  onclick="x_admin_show('排班管理','tech_work_list',800,600)">数据导出</button>
        <!-- 
        <button class="layui-btn layui-btn-disabled turn_type_list" onclick="x_admin_show('轮排方式','turn_type_list',800,600)"><i class="layui-icon"></i>轮排方式</button> -->
        </div>
        <!-- serch -->
         <div class="layui-row  search" style="width: 50%;float: left;">
              
            <form class="layui-form layui-col-md12 x-so">
              <input class="layui-input" placeholder="输入要查询的门店名" name="start" id="search">
              
              <button class="layui-btn"  data-type="reload" id="btn1"><i class="layui-icon">&#xe615;</i></button>
            </form>
        
        </div> 
        <span class="x-right" style="line-height:40px"></span>
      </xblock>


  	   <table id="demo" lay-filter="test"></table>

    </div>
    <script type="text/html" id="test">
          <button class="layui-btn layui-btn-sm layui-btn-disabled  suggest_edit" lay-event="edit" >处理</button>
           <button class="layui-btn layui-btn-sm layui-btn-disabled  suggest_show" lay-event="show" >发布</button>
         
    </script>
    <script type="text/html" id="status">
      {{#  if(d.status ==0){ }}
    <span style="color: #F581B1;">未处理</span>
      {{#  }if(d.status==1) { }} 
     <span style="">已处理</span>
      {{#  }if(d.status==2){ }} 
      <span style="color: green;">已发布</span>
      {{#  } }} 
    </script>
    <script>
		layui.use('table', function(){
		  var table = layui.table;
		  
		  //渲染表格
		  table.render({
		    elem: '#demo'
		    ,height:'full-160'
		    ,url: '/data/json/suggest_list/' //数据接口
		    ,page: true //开启分页
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,id: 'employee'
        ,limit:15
		    ,cols: [[ //表头
          {checkbox: true, fixed: true}
		      ,{field: 'id', title: 'ID',  sort: true , fixed: true,width:100}
          ,{field: 'store_id', title: '门店' ,width:120}
		      ,{field: 'content', title: '内容' ,width:120}
          ,{field: 'user', title: '投诉人' ,width:120}
          ,{field: 'phone', title: '联系方式' }
          ,{field: 'add_time', title: '提交时间' }
          ,{field: 'status', title: '状态',toolbar:'#status' }
          ,{field: 'reply_content', title: '处理结果' }
          ,{field: 'reply_user', title: '处理者' }
          ,{field: 'reply_time', title: '处理时间' }
		      ,{field: '', title: '操作',toolbar: '#test',width:160} 
		    ]]
        ,done:function(){
          // 按钮权限检测
          var arr=['suggest_store_list','suggest_edit','suggest_show'];
          var jsonData = JSON.parse($("#check").html());
          for(var i in arr){
            jsonData.func = arr[i];
            //console.log('jsonData',jsonData);
            button_check(jsonData); 
          }
        }
		  });
          var $ = layui.$, active = {
            reload: function(){
              
              
              //执行重载
              table.reload('employee', {
                page: {
                  curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    search: $("#search").val()
                }
              });
            }
          };
        
          $('.search .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
            return false;
          });


          table.on('tool(test)', function(obj){ 
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
              if(layEvent === 'edit'){
                  x_admin_show('建议答复','suggest_edit?id='+data.id,800,600);
              }
              if(layEvent === 'show'){ //删除
                  layer.confirm('确认要发布到小程序吗', function(index){
                    //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    if(data.status!=1){
                      layer.msg('该条没有处理或者已经发布');
                      return false;
                    }
                    console.log(data);
                    $.post('suggest_show',data,function(res){
                      if(res.status){
                        layer.msg(res.msg);
                         setTimeout(function(){
                          window.location.reload(); //刷新当前窗口
                          //parent.layer.close(index); //再执行关闭 
                        },2000);
                      }else{
                        layer.msg(res.msg);
                      }},'json');
                      layer.close(index);
                      });
              } 
          });

        
});
		  
	</script>
    
  <script type="text/javascript">
    $(document).keydown(function(event){
        switch(event.keyCode){
           case 13: $('.search .layui-btn').click();
           }
    });

  </script>
